<template>
	<view class="content">
		<!-- 轮播图区域 -->
		<swiper indicator-dots  autoplay circular>
			<swiper-item v-for="(item, index) in swipers" :key="index">
				<image :src="item.image" mode="scaleToFill"></image>
			</swiper-item>
		</swiper>
		
		<!-- nav导航区域 -->
		<view class="nav-area">
			<view v-for="(item, index) in navList" :key="index" @click="gotoPage(item)">
				<view :class="item.icon"></view>
				<text>{{item.name}}</text>
			</view>
			
		</view>
		
		<!-- 推荐好物区域 -->
		<view class="hot_goods">
			<!-- 头部 -->
			<view class="hot_title">
				<text>推荐好物</text>
			</view>
			
			<!-- 商品列表 -->
			<goods-list :goodsList="goodsList"></goods-list>
			
		</view>
	</view>
</template>

<script>
	import GoodsList from '../../components/goodslist/GoodsList.vue'
	export default {
		components: {
			GoodsList,
		},
		data () {
			return {
				swipers: [],//轮播图数据
				goodsList: [], //商品数据
				navList: [//导航信息
					{
						icon: "iconfont icon-ziyuan",
						name: "好物超市",
						path: "../goods/goods"
					},
					{
						icon: "iconfont icon-guanyuwomen",
						name: "联系我们",
						path: "../index/AboutUs/AboutUs"
					},
					{
						icon: "iconfont icon-tupian",
						name: "商品分类",
						path: "../index/pics/pics"
					},
					{
						icon: "iconfont icon-shipin",
						name: "学习视频",
						path: "/pages/videos/videos"
					}
				],
				pageNum: 0
				
			}
		},
		methods: {
			//获取轮播图数据
			async getSwipers() {

				const result = await uni.request({
					url: 'http://localhost:4000/swiper'
				})
				console.log(result)

				this.swipers = result[1].data.data.banner.list
				
			},
			
			//获取商品列表数据
			async getGoodsList() {
				this.pageNum++

				const data = await uni.request({
					url: `http://localhost:4000/goods?type=pop&page=${this.pageNum}`
				})
				console.log(data[1])
				this.goodsList = [...this.goodsList,...data[1].data.data.list]
				
			},
			//导航页面跳转
			gotoPage(item){
				uni.navigateTo({
					url: item.path
				})
			}
		},
		//加载页面生命周期函数发送数据请求
		onLoad() {
			this.getSwipers()
			this.getGoodsList()
			
		},
		onReachBottom() {
			this.getGoodsList()
		}
	}
</script>

<style lang="scss">
	@import "../../static/font_nav/iconfont.css";
	.content {
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				height: 100%;
				width: 100%;
			}
		}
		.nav-area{
			
			display: flex;
			text-align: center;
			
			>view {
				flex: 1;
				margin-bottom: 20rpx;
				view {
					margin: 15rpx auto;
					
					width: 120rpx;
					height: 120rpx;
					line-height: 120rpx;
					background-color: $shop_color;
					color: #fff;
					font-size: 50rpx;
					border-radius: 60rpx;
				}
				text{
					font-size: 30rpx;
				}
			}
			
			
		}
	}
	.hot_goods{
		width: 750rpx;
		background-color: #eee;
		overflow: hidden;
		.hot_title {
			text-align: center;
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 40rpx;
			letter-spacing: 15rpx;
			color:$shop_color;
			background-color: #fff;
			margin: 10rpx 0;
			
		}
	}

	
	
</style>
